package com.poolsoft.callblocker;

import java.lang.reflect.Method;

import com.android.internal.telephony.ITelephony;
import com.android.internal.util.*;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class Blocker extends BroadcastReceiver {
 Context context = null;
 private static final String TAG = "Phone on Call";
 private ITelephony telephony;

 @Override
 public void onReceive(Context context, Intent intent) {
  Log.v(TAG, "Receving....");
  TelephonyManager telephonymanager= (TelephonyManager)
  context.getSystemService(Context.TELEPHONY_SERVICE); 
  try {
   Class c = Class.forName(telephony.getClass().getName());
   Method m = c.getDeclaredMethod("getITelephony");
   m.setAccessible(true);
   
   telephony = (ITelephony) m.invoke(telephonymanager);
   myToast(telephony.toString());
   telephony.silenceRinger();
   telephony.endCall();
  } catch (Exception e) {
   e.printStackTrace();
  }
 
 }
 
 public void myToast(String text){
 Toast toast = Toast.makeText(getApplicationContext(),"\n"+text+"\n", Toast.LENGTH_LONG);
 toast.setGravity(Gravity.BOTTOM, 0, 0);
 LinearLayout toastView = (LinearLayout) toast.getView();
 ImageView imageCodeProject = new ImageView(getApplicationContext());
 //imageCodeProject.setImageResource(R.drawable.icon);
 //toastView.addView(imageCodeProject, 0);
 toast.show();	
 }

private Context getApplicationContext() {
	// TODO Auto-generated method stub
	return null;
}


}
